<template>
    <!-- <div class="cc-dialog" :style="{display: isShown?'flex':'none'}"> -->
    <div class="cc-dialog" v-show="isShown">
        <div class="container" :style="{width: width+'px'}">
            <div class="title">{{ title }}</div>
            <!-- {{  }}  执行e.innerText赋值 -->
            <!-- <div class="content">{{ content }}</div> -->
            <!-- v-html  执行e.innerHTML赋值 -->
            <div class="content" v-html="content"></div>
            <span class="button" @click="emit('close', {timestamp:Date.now(), reason:'closeButton'})">关闭</span>
        </div>
    </div>
</template>

<script setup lang="ts">
//自定义组件的属性: 对于当前组件来说，都是只读的数据，不能修改 —— “单向数据流”
//口诀：父子组件传递数据使用“PropsDown，EventsUp”
// defineProps(['title', 'content'])
defineProps({
    title: {
        type: String,
        required: false,
        default: '提示'
    },
    content: {
        type: String,
        required: true
    },
    width: {
        type: Number,
        required: false,
        default: 300
    },
    isShown: {
        type: Boolean,
        required: false,
        default: false
    }
})

//自定义事件
const emit = defineEmits(['open', 'close'])

</script>

<style scoped>
.cc-dialog {
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
}
.container {
    background-color: #fff;
    /* width: 300px; */
    border-radius: 4px;
    box-shadow: 0 0 10px #999;
    padding: 15px;
    display: flex;
    flex-direction: column;
}
.title {
    font-weight: bold;
    padding-bottom: 10px;
    border-bottom: 1px solid #aaa;
}
.content {
    padding: 15px 0;
}
.button {
    width: 80px;
    align-self: center;
    margin-top: 15px;
}

</style>